package main

import (
	"awesomeProject/zinx"
	"awesomeProject/zinx/utils"
	"awesomeProject/zinx/ziface"
	"fmt"
)

type PingRouter struct {
	zinx.BaseRouter
}

type HelloRouter struct {
	zinx.BaseRouter
}

func (this *HelloRouter) Handle(request ziface.IRequest)  {
	fmt.Println("11111 Call hello Router Handle")
	err := request.GetConnection().SendMsg(1,[]byte("我是服务器2"))
	if err != nil {
		fmt.Println("call back before ping err",err)
	}
}

//func (this *PingRouter) PreHandle(request ziface.IRequest)  {
//	fmt.Println("Call Router PreHandle")
//	err := request.GetConnection().SendMsg(1,[]byte("sdfsadfsadfsa"))
//	if err != nil {
//		fmt.Println("call back before ping err",err)
//	}
//}

func (this *PingRouter) Handle(request ziface.IRequest)  {
	fmt.Println("Call Router Handle")
	err := request.GetConnection().SendMsg(0,[]byte("我是服务器1"))
	if err != nil {
		fmt.Println("call back before ping err",err)
	}
}

//func (this *PingRouter) PostHandle(request ziface.IRequest)  {
//	fmt.Println("Call Router PostHandle")
//	_,err := request.GetConnection().GetTcpConnection().Write([]byte("post  ping ..."))
//	if err != nil {
//		fmt.Println("call back post...ping err",err)
//	}
//}

func main() {
	s := zinx.NewServer(utils.GlobalObject.Name)
	s.AddRouter(0,&PingRouter{})
	s.AddRouter(1,&HelloRouter{})
	s.Server()

}
